﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using BlueCMS.Core.Data.Query.Conditions;

namespace BlueCMS.Core.Data.Query.Tables
{
    public class JoinTable : Table, IJoinTable
    {
        public Table JoinedWith { get; set; }
        public JoinType Type { get; set; }
        public ConditionChain Condition { get; set; }

        public JoinTable(string name, Table joinedWith, JoinType type) : base(name)
        {
            JoinedWith = joinedWith;
            Type = type;
        }

        public new IJoinTable As(string alias)
        {
            base.As(alias);
            return this;
        }

        //public IJoinTable On(object nameOrExpressionLHS, MultiOperators op, params object[] nameOrExpressionRHS)
        //{
        //    Condition = new ConditionChain();
        //    Condition.Condition(nameOrExpressionLHS, op, nameOrExpressionRHS);
        //    return this;
        //}

        //public IJoinTable On(object nameOrExpressionLHS, BinaryOperators op, object nameOrExpressionRHS)
        //{
        //    Condition = new ConditionChain();
        //    Condition.Condition(nameOrExpressionLHS, op, nameOrExpressionRHS);
        //    return this;
        //}

        //public IJoinTable On(object nameOrExpression, UnaryOperators op)
        //{
        //    Condition.Condition(nameOrExpression, op);
        //    return this;
        //}

        public IJoinTable On(Action<IStartNode> condition)
        {
            Condition = new ConditionChain();
            condition(Condition);
            return this;
        }
    }
}
